/**
 * Created by Jackie.Chen on 2016/12/4.
 */

var Init = function () {
    /*基础配置*/
    var el = 'body';

    /*删除兴趣*/
    function delEnt(){
        var $this = $(this);
        $this.parents('li').remove();
        var entName = $this.siblings('span').eq(0).text();
        $.each($('#chooseEnt li'),function(){
            var me = $(this);
            if(me.find('span').eq(0).text() == entName){
                me.removeClass('ent-br');
            }
        });
    }
    function chooseEnt(){
        var $this = $(this);
        $this.click(function() {
            if (!$this.is('.ent-br')) {
                $this.addClass('ent-br');
                $('.choose-item').eq(0).append('<li class="ent-br" data="'+ $this.attr("data")+'"><span class="ent-name" title="'+$this.find('span').eq(0).text()+'">' + $this.find('span').eq(0).text() + '</span><span class="ico1"></span></li>');
            }
        });
    }

    function confirm() {
        var name = "";
        $('.choose-item').eq(0).find('li').each(function(){
            var $this = $(this);
            name += $this.attr('data')+',';
        });
        if(name == ""){
            layer.msg("请至少选择一项感兴趣的行业！");
            return;
        }
         var dataparam = {
             "userid":  userInfo.userid,
             "intrestIndus": name,
             "industryin":$('.industry_select').val()
         };
         ajaxCommonFun({
             type: 'POST',
             url: '/user/updateUserInfo.do',
             data: dataparam,
             success: function (t) {
                 if (t.status == 'ERROR') {
                     layer.msg(t.message);
                 } else {
                    // layer.msg(t.result);
                     location.href="/#/product/situation";
                 }
             }
         });
     }
    /*end分页*/
    /*页面初始化和事件绑定*/
    function bindEvents() {
        $(el).undelegate()
            .delegate('.ico1','click',delEnt)
            .delegate('#confirm','click',confirm);
    }

    /*页面初始化*/
    function init() {
        bindEvents();
        $.each($('#chooseEnt li'),chooseEnt);
    }
    /*end 页面初始化*/
    init();
};
